﻿//AJAX使用
function getHTTPObject() {
    var xmlHttp;
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
        //如果用户使用IE，就返回XMLHTTP的ActiveX对象
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        //否则返回一个XMLHttpRequest对象
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}
var xmlHttp = getHTTPObject();
/**************************************************************************************************************************************************/
var fileTotal = null; //弹出选择文件对话框所选择的文件数(暂作为进入队列数,因为超过上传数量时就会报错误的并且也不会上传)或选择文件数+已有附件数
var varTotal = 1; //动态上传文件的数量
var totalRows = null; //上传附件内容的总行数(计算得出)
var varRow = 1; //动态上传文件对应的行数
var newFileName = ""; //上传到临时文件夹产生的新文件名
var popDialogCount = 0; //弹出选择文件框次数,控制显示TD的id不重复
var upFlag = "Add"; //弹出选择文件框添加文件时是新增还是编辑添加的标识符
var colIdFlag = ""; //显示TD的id(部分标识内容)
var tbTdOldArr = null; //之前上传附件的内容(id+| +td里内容的形式)
var isSameFlag = "NO"; // 存在相同文件是否替换标志
var varSameFlag = 0; // 存在相同文件替换数量
function fileQueueError(file, errorCode, message) {
    //debugger;
    try {
        var errorName = "";
        if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
            errorName = "You have attempted to queue too many files.";
        }

        if (errorName !== "") {
            Ext.Msg.alert('提示', errorName);
            return;
        }

        switch (errorCode) {
            case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
                if (upLimit != 1)
                    Ext.Msg.alert('提示', '待上传文件列表数量超限，不能选择！');
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                Ext.Msg.alert('提示', '该文件大小为0，不能选择！');
                break;
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                Ext.Msg.alert('提示', '上传文件过大了！');
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
            default:
                Ext.Msg.alert('提示', message);
                break;
        }
    } catch (ex) {
        this.debug(ex);
    }
}
function fileDialogStart() {
    var objTable = document.getElementById("tbUpResult");
    var objTableBody = objTable.getElementsByTagName("TBODY")[0];
    if (objTableBody.innerHTML != "" && upLimit == 1)//首次进来
    {
        this.setFileUploadLimit(1);
        Ext.Msg.alert('提示', '只允许1个上传文件，不能选择上传了！');
    }
    if (objTableBody.innerHTML == "" && upLimit == 1)
        this.setFileUploadLimit(0); //动态修改设置中的file_upload_limit，特殊值0表示无限制
}
function fileDialogComplete(numFilesSelected, numFilesQueued) {
    try {
        if (numFilesQueued > 0) {
            var selectedTotal = numFilesSelected;
            popDialogCount = popDialogCount + 1;
            var objTable = document.getElementById("tbUpResult");
            var objTableBody = objTable.getElementsByTagName("TBODY")[0];
            if (objTableBody.innerHTML != "")//首次进来为修改时
            {
                if (upLimit == 1)
                    this.cancelUpload();
                else {
                    upFlag = "Upd";
                    colIdFlag = popDialogCount.toString() + "Upd";
                    var tbCells = objTable.cells;
                    var tbCellLength = tbCells.length;
                    tbTdOldArr = new Array(tbCellLength);
                    for (var j = 0; j < tbCellLength; j++) {
                        tbTdOldArr[j] = tbCells[j].id + "|" + tbCells[j].innerHTML;
                    }
                    fileTotal = selectedTotal + tbCellLength;
                    totalRows = Math.ceil(fileTotal / 3);
                    //置为初始值
                    varTotal = 1;
                    varRow = 1;
                    DeleteRowTable(); //删除所有,等待再加
                    this.startUpload();
                }
            }
            else {
                upFlag = "Add";
                colIdFlag = popDialogCount.toString() + "Add";
                fileTotal = selectedTotal;
                totalRows = Math.ceil(fileTotal / 3);
                //置为初始值
                varTotal = 1;
                varRow = 1;
                this.startUpload();
            }
        }
    } catch (ex) {
        this.debug(ex);
    }
}

function uploadProgress(file, bytesLoaded) {

    try {
        var percent = Math.ceil((bytesLoaded / file.size) * 100);

        var progress = new FileProgress(file, this.customSettings.upload_target);
        progress.setProgress(percent);
        if (percent === 100) {
            progress.setStatus("Creating thumbnail...");
            progress.toggleCancel(false, this);
        } else {
            progress.setStatus("Uploading...");
            progress.toggleCancel(true, this);
        }
    } catch (ex) {
        this.debug(ex);
    }
}

function uploadSuccess(file, serverData) {
    try {
        var fileConArr = serverData.split('|');
        newFileName = fileConArr[0]; //获取产生的文件新名字
        var conName = conPreName + '_Hdn_SaveFilesInfo';
        if (document.getElementById(conName).value != "")
            document.getElementById(conName).value = document.getElementById(conName).value + "," + file.name + "|" + serverData;
        else
            document.getElementById(conName).value = file.name + "|" + serverData;
        //alert(document.getElementById(conName).value);
        var progress = new FileProgress(file, this.customSettings.upload_target);

        progress.setStatus("Thumbnail Created.");
        progress.toggleCancel(false);


    } catch (ex) {
        this.debug(ex);
    }
}

function uploadComplete(file) {
    try {
        /*  I want the next upload to continue automatically so I'll call startUpload here */
        if (this.getStats().files_queued > 0) {
            this.startUpload();
        } else {
            var progress = new FileProgress(file, this.customSettings.upload_target);
            progress.setComplete();
            progress.setStatus("All files received.");
            progress.toggleCancel(false);
        }
        var imageNamePath = SetfilePic(file.name);
        addTableContentFun(imageNamePath, file.name);
        UploadCompleted_Event(file.name, file.type, file.size, 'add'); //当主页面有这个函数时就执行主页面相关得操作
    } catch (ex) {
        this.debug(ex);
    }
}

function uploadError(file, errorCode, message) {
    var progress;
    try {
        switch (errorCode) {
            case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
                try {
                    progress = new FileProgress(file, this.customSettings.upload_target);
                    progress.setCancelled();
                    progress.setStatus("Cancelled");
                    progress.toggleCancel(false);
                }
                catch (ex1) {
                    this.debug(ex1);
                }
                break;
            case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
                try {
                    progress = new FileProgress(file, this.customSettings.upload_target);
                    progress.setCancelled();
                    progress.setStatus("Stopped");
                    progress.toggleCancel(true);
                }
                catch (ex2) {
                    this.debug(ex2);
                }
            case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
                Ext.Msg.alert('上传错误提示', 'uploadlimit！');
                break;
            default:
                Ext.Msg.alert('上传错误提示', message);
                break;
        }
    } catch (ex3) {
        this.debug(ex3);
    }

}
function UploadCompleted_Event(name, type, size, flag) {

}
//获得对应文件图片
function SetfilePic(name) {
    filepath = "../images/fileupload/";
    var t = name.split(".");
    var hz = t[t.length - 1];
    switch (hz.toLowerCase()) {
        case "doc": t = "msword.gif"; break;
        case "xls": t = "msexcel.gif"; break;
        case "jpg": t = "image.gif"; break;
        case "gif": t = "image.gif"; break;
        case "bmp": t = "image.gif"; break;
        case "png": t = "image.gif"; break;
        case "rar": t = "archive.gif"; break;
        case "zip": t = "archive.gif"; break;
        case "htm": t = "htm.gif"; break;
        case "html": t = "htm.gif"; break;
        case "js": t = "htm.gif"; break;
        case "asp": t = "htm.gif"; break;
        case "aspx": t = "htm.gif"; break;
        case "xml": t = "htm.gif"; break;
        default: t = "unknown.gif";
    }
    return filepath + t;
}
//输入当前所在行号和当前要添加的文件数,算出当前文件对应的行数
function IsThisRow(curRows, curTotal) {
    var temp = true;
    var oldRow = Math.ceil((curTotal - 1) / 3);
    if (curRows == oldRow)
        temp = true;
    else
        temp = false;
    return temp;
}

///添加(设置)文件到table
function SetTableDiv(imgPath, fileName, type) {
    //debugger;
    var objTable = document.getElementById("tbUpResult");
    var objTableBody = objTable.getElementsByTagName("TBODY")[0];
    var row = null;
    var col = null;
    var newRow = null;
    var rowIndex = null;
    var colIdStr = "";
    if (upFlag == "Add") {
        if (fileTotal > 3) {
            if (varTotal == 1)
                row = document.createElement("TR");
            else {
                if (IsThisRow(varRow, varTotal))
                    row = objTableBody.children[varRow - 1];
                else
                    row = document.createElement("TR")
            }
            col = document.createElement("TD");
            colIdStr = "col" + colIdFlag + varTotal.toString();
            col.id = colIdStr;
            col.style.width = "33%";
            varTotal = varTotal + 1;
            row.appendChild(col);
            objTableBody.appendChild(row);
            newRow = Math.ceil(varTotal / 3);
            if (newRow != varRow)
                varRow = varRow + 1;
        }
        else {
            if (varTotal == 1)
                row = document.createElement("TR")
            else {
                row = objTableBody.children[0];
            }
            col = document.createElement("TD")
            colIdStr = "col" + colIdFlag + varTotal.toString();
            col.id = colIdStr;
            col.style.width = "33%";
            varTotal = varTotal + 1;
            row.appendChild(col);
            objTableBody.appendChild(row);
        }
        rowIndex = varRow - 1;
        addNewTd(imgPath, fileName, rowIndex, colIdStr, type); //新增TD赋值
    }
    else {
        for (var t = 0; t < tbTdOldArr.length; t++) {
            if (tbTdOldArr[t].indexOf(fileName) > 0) {
                if (confirm(fileName + ' 存在相同文件，是否替换？')) {
                    if (objTableBody.innerHTML != "") {
                        var tbCells = objTable.cells;
                        var tbCellLength = tbCells.length;
                        tbTdOldArr = new Array(tbCellLength);
                        for (var j = 0; j < tbCellLength; j++) {
                            tbTdOldArr[j] = tbCells[j].id + "|" + tbCells[j].innerHTML;
                        }
                        varTotal = 1;
                        varRow = 1;
                        DeleteRowTable(); //删除所有,等待再加
                    }
                    GetUpFileList(fileName); //重新获取保存所用的隐藏域内容
                    var temp = tbTdOldArr[t];
                    tbTdOldArr.remove(temp);
                    var start = temp.indexOf('id=');
                    var end = temp.indexOf('type');
                    var oldName = temp.substring(start + 3, end - 5);
                    realDelTmpFile(oldName); //删除对应临时文件夹中的文件

                    //替换相同时
                    varSameFlag = varSameFlag + 1;
                    isSameFlag = "YES";
                    break;
                }
            }
        }
        if (fileTotal > 3) {
            while (varTotal <= tbTdOldArr.length) {
                for (var k = 0; k < tbTdOldArr.length; k++) {
                    if (varTotal == 1)
                        row = document.createElement("TR");
                    else {
                        if (IsThisRow(varRow, varTotal))
                            row = objTableBody.children[varRow - 1];
                        else
                            row = document.createElement("TR")
                    }
                    var col = document.createElement("TD");
                    var tdStr = tbTdOldArr[k].split('|');
                    col.id = tdStr[0];
                    col.style.width = "33%";
                    varTotal = varTotal + 1;
                    row.appendChild(col);
                    objTableBody.appendChild(row);
                    var start = tdStr[1].indexOf('(');
                    var end = start + 2;
                    var newTdStr = tdStr[1].substring(0, start + 1) + (varRow - 1) + tdStr[1].substring(end, tdStr[1].length);
                    document.getElementById(col.id).innerHTML = newTdStr;
                    newRow = Math.ceil(varTotal / 3);
                    if (newRow != varRow)
                        varRow = varRow + 1;
                }
            }
            if (IsThisRow(varRow, varTotal))
                row = objTableBody.children[varRow - 1];
            else
                row = document.createElement("TR")
            col = document.createElement("TD");
            colIdStr = "col" + colIdFlag + varTotal.toString();
            //有相同文件替换时的ID
            if (isSameFlag == "YES") {
                colIdStr = colIdStr + varSameFlag.toString();
                isSameFlag = "NO";
            }
            col.id = colIdStr;
            col.style.width = "33%";
            varTotal = varTotal + 1;
            row.appendChild(col);
            objTableBody.appendChild(row);
            rowIndex = varRow - 1;
            newRow = Math.ceil(varTotal / 3);
            if (newRow != varRow)
                varRow = varRow + 1;
            addNewTd(imgPath, fileName, rowIndex, colIdStr, type); //新增TD赋值
        }
        else {
            while (varTotal <= tbTdOldArr.length) {
                row = document.createElement("TR");
                for (var i = 0; i < tbTdOldArr.length; i++) {
                    col = document.createElement("TD");
                    var tdStr = tbTdOldArr[i].split('|'); ;
                    col.id = tdStr[0];
                    col.style.width = "33%";
                    varTotal = varTotal + 1;
                    row.appendChild(col);
                    objTableBody.appendChild(row);
                    var start = tdStr[1].indexOf('(');
                    var end = start + 2;
                    var newTdStr = tdStr[1].substring(0, start + 1) + "0" + tdStr[1].substring(end, tdStr[1].length);
                    document.getElementById(col.id).innerHTML = newTdStr;
                }
            }
            row = objTableBody.children[0];
            col = document.createElement("TD")
            colIdStr = "col" + colIdFlag + varTotal.toString();
            col.id = colIdStr;
            col.style.width = "33%";
            varTotal = varTotal + 1;
            row.appendChild(col);
            objTableBody.appendChild(row);
            rowIndex = varRow - 1;
            addNewTd(imgPath, fileName, rowIndex, colIdStr, type); //新增TD赋值
        }
    }
}

//新增TD赋值
function addNewTd(imgPath, fileName, rowIndex, colIdStr, type) {
    var openUrl = "../UserControl/OpenFile.aspx?name=" + encodeURIComponent(fileName) + "&id=" + newFileName + "&type=" + type;
    var newContent = "";
    //    if (swfu.settings.button_disabled)//是否为只读,只读的话不加 移除 功能
    //        newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='" + openUrl + "' target='_blank'>" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)'></a>";
    //    else
    //        newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='" + openUrl + "' target='_blank'>" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)' onclick='delFile(" + rowIndex + "," + colIdStr + ",\"" + newFileName + "\"," + type + ",\"" + fileName + "\")'><span class='STYLE4'>×</span> 移除</a>";
    if (swfu.settings.button_disabled)//是否为只读,只读的话不加 移除 功能
    {
      //fx  if (newFileName.indexOf('.doc') > 0 || newFileName.indexOf('.xls') > 0)
      //fx      newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='javascript:void(0)' onclick='openOffFileFun(3,\"" + newFileName + "\",\"" + fileName + "\")'>" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)'></a>";
      //fx  else
             newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='" + openUrl + "' target='_blank'>" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)'></a>";
            //newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='javascript:void(0)' target='_blank'>" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)'></a>";
    }
    else {
      //fx  if (newFileName.indexOf('.doc') > 0 || newFileName.indexOf('.xls') > 0)
      //fx      newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='javascript:void(0)' onclick='openOffFileFun(1,\"" + newFileName + "\",\"" + fileName + "\")' >" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)' onclick='delFile(" + rowIndex + "," + colIdStr + ",\"" + newFileName + "\"," + type + ",\"" + fileName + "\")'><span class='STYLE4'>×</span> 移除</a>";
      //fx  else
            newContent = "<img border=0 src='" + imgPath + "'width=16 height=16><a href='" + openUrl + "' target='_blank'>" + fileName + "&nbsp;&nbsp;</a><a href='javascript:void(0)' onclick='delFile(" + rowIndex + "," + colIdStr + ",\"" + newFileName + "\"," + type + ",\"" + fileName + "\")'><span class='STYLE4'>×</span> 移除</a>";
    }
    document.getElementById(colIdStr).innerHTML = newContent;
}
function addTableContentFun(imgPath, fileName) {
    //debugger;
    SetTableDiv(imgPath, fileName, 0);
}
function openOffFileFun(type,newFileName, fileName) {
    var hostName = window.location.protocol + "//" + window.location.host;
    var url = "../UserControl/OpenFile.aspx?type=-2&newName=" + escape(newFileName);
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            if (xmlHttp.status == 200) {
                var path = xmlHttp.responseText;
                parent.parent.OpenOfficeDoc(type, hostName + '/WebSource/TmpFile/' + newFileName, hostName + '/WebSource/lyupfile.asp', fileName, path + '\\' + newFileName);
                return;
            }
        }
    };
    xmlHttp.setRequestHeader("If-Modified-Since", "0");  
    xmlHttp.send(null);
}
function realDelTmpFile(newName) {
    var url = "../UserControl/OpenFile.aspx?type=-1&newName=" + escape(newName);
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = function() { };
    xmlHttp.setRequestHeader("If-Modified-Since", "0");  //加这
    xmlHttp.send(null);
}
function delFile(rowIndex, colIdStr, newName, type, oldName) {
    //debugger;
    try {
        var objTable = document.getElementById("tbUpResult");
        var objTableBody = objTable.getElementsByTagName("TBODY")[0];
        var row = objTableBody.children[rowIndex];
        var col = row.children.namedItem(colIdStr.id);
        row.removeChild(col);
        if (type == 0)
            realDelTmpFile(newName); //删除对应临时文件夹中的文件
        else {
            var delFCon = conPreName + '_Hdn_SavedDelFiles';
            if (document.getElementById(delFCon).value != "")
                document.getElementById(delFCon).value = document.getElementById(delFCon).value + "|" + newName;
            else
                document.getElementById(delFCon).value = newName;
        }
        GetUpFileList(newName); //重新获取保存所用的隐藏域内容
        ReshAfterSave("deleted");
        UploadCompleted_Event(oldName, '', '', 'del');
    } catch (ex) {
        this.debug(ex);
    }
}
function GetUpFileList(newName) {
    var conName = conPreName + '_Hdn_SaveFilesInfo';
    var upFileArr = document.getElementById(conName).value.split(',');
    for (var m = 0; m < upFileArr.length; m++) {
        if (upFileArr[m].indexOf(newName) >= 0) {
            upFileArr.remove(upFileArr[m]);
            break;
        }
    }
    document.getElementById(conName).value = "";
    for (var n = 0; n < upFileArr.length; n++) {
        if (document.getElementById(conName).value != "")
            document.getElementById(conName).value = document.getElementById(conName).value + "," + upFileArr[n];
        else
            document.getElementById(conName).value = upFileArr[n];
    }
}
//删除所有记录
function DeleteRowTable() {
    var objTable = document.getElementById("tbUpResult");
    if (objTable == null) {
        return;
    }
    var j = objTable.rows.length;
    for (var i = j - 1; i >= 0; i--) {
        objTable.deleteRow(i);
    }
}
function BindRecordByUpd(result) {
    //debugger;
    fileTotal = null;
    varTotal = 1;
    totalRows = null;
    varRow = 1;
    newFileName = "";
    popDialogCount = 0;
    upFlag = "Add";
    colIdFlag = "";
    tbTdOldArr = null;
    isSameFlag = "NO";
    varSameFlag = 0;
    DeleteRowTable(); //上面代码为重新初始化

    var conName = conPreName + '_Hdn_SaveFilesInfo';
    document.getElementById(conName).value = result;
    var upFileArr = result.split(',');
    var imageNamePath = "";
    var upFileGroup = null;
    fileTotal = upFileArr.length;
    totalRows = Math.ceil(fileTotal / 3);
    for (var m = 0; m < upFileArr.length; m++) {
        upFileGroup = upFileArr[m].split('|');
        imageNamePath = SetfilePic(upFileGroup[0]);
        newFileName = upFileGroup[1];
        SetTableDiv(imageNamePath, upFileGroup[0], 1);
    }
}

function DeleteAttar(){

 DeleteRowTable();
 var conName = conPreName + '_Hdn_SaveFilesInfo';
    document.getElementById(conName).value = '';
}

function ReshAfterSave(flag) {
    var objTable = document.getElementById("tbUpResult");
    var objTableBody = objTable.getElementsByTagName("TBODY")[0];
    var tbCells = objTable.cells;
    var tbCellLength = tbCells.length;
    var tbTdArr = new Array(tbCellLength);
    for (var j = 0; j < tbCellLength; j++) {
        tbTdArr[j] = tbCells[j].id + "|" + tbCells[j].innerHTML;
    }
    DeleteRowTable(); //页面上删除所有
    if (tbCellLength > 3) {
        var totalRs = Math.ceil(tbCellLength / 3);
        var varTRs = 1; //动态个数
        var varRs = 1; //动态行数
        for (var k = 0; k < tbCellLength; k++) {
            if (varTRs == 1)
                newRow = document.createElement("TR");
            else {
                if (IsThisRow(varRs, varTRs))
                    newRow = objTableBody.children[varRs - 1];
                else
                    newRow = document.createElement("TR")
            }
            var newCol = document.createElement("TD");
            var tdStr = tbTdArr[k].split('|'); ;
            newCol.id = tdStr[0];
            newCol.style.width = "33%";
            varTRs = varTRs + 1;
            newRow.appendChild(newCol);
            objTableBody.appendChild(newRow);
            var start = tdStr[1].indexOf('(');
            var end = start + 2;
            var newTdStr = tdStr[1].substring(0, start + 1) + (varRs - 1) + tdStr[1].substring(end, tdStr[1].length);
            if (flag == 'saved')
                newTdStr = newTdStr.replace('type=0', 'type=1'); //保存后修改文件连接参数
            document.getElementById(newCol.id).innerHTML = newTdStr;
            var newRs = Math.ceil(varTRs / 3);
            if (newRs != varRs)
                varRs = varRs + 1;
        }
    }
    else {
        newRow = document.createElement("TR");
        for (var i = 0; i < tbCellLength; i++) {
            var newCol = document.createElement("TD");
            var tdStr = tbTdArr[i].split('|'); ;
            newCol.id = tdStr[0];
            newCol.style.width = "33%";
            newRow.appendChild(newCol);
            objTableBody.appendChild(newRow);
            var start = tdStr[1].indexOf('(');
            var end = start + 2;
            var newTdStr = tdStr[1].substring(0, start + 1) + "0" + tdStr[1].substring(end, tdStr[1].length);
            if (flag == 'saved')
                newTdStr = newTdStr.replace('type=0', 'type=1'); //保存后修改文件连接参数
            document.getElementById(newCol.id).innerHTML = newTdStr;
        }
    }
}
function fadeIn(element, opacity) {
    var reduceOpacityBy = 5;
    var rate = 30; // 15 fps


    if (opacity < 100) {
        opacity += reduceOpacityBy;
        if (opacity > 100) {
            opacity = 100;
        }

        if (element.filters) {
            try {
                element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
            } catch (e) {
                // If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
                element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
            }
        } else {
            element.style.opacity = opacity / 100;
        }
    }

    if (opacity < 100) {
        setTimeout(function() {
            fadeIn(element, opacity);
        }, rate);
    }
}


/* ******************************************
*	FileProgress Object
*	Control object for displaying file info
* ****************************************** */

function FileProgress(file, targetID) {
    this.fileProgressID = "divFileProgress";

    this.fileProgressWrapper = document.getElementById(this.fileProgressID);
    if (!this.fileProgressWrapper) {
        this.fileProgressWrapper = document.createElement("div");
        this.fileProgressWrapper.className = "progressWrapper";
        this.fileProgressWrapper.id = this.fileProgressID;

        this.fileProgressElement = document.createElement("div");
        this.fileProgressElement.className = "progressContainer";

        var progressCancel = document.createElement("a");
        progressCancel.className = "progressCancel";
        progressCancel.href = "#";
        progressCancel.style.visibility = "hidden";
        progressCancel.appendChild(document.createTextNode(" "));

        var progressText = document.createElement("div");
        progressText.className = "progressName";
        progressText.appendChild(document.createTextNode(file.name));

        var progressBar = document.createElement("div");
        progressBar.className = "progressBarInProgress";

        var progressStatus = document.createElement("div");
        progressStatus.className = "progressBarStatus";
        progressStatus.innerHTML = "&nbsp;";

        this.fileProgressElement.appendChild(progressCancel);
        this.fileProgressElement.appendChild(progressText);
        this.fileProgressElement.appendChild(progressStatus);
        this.fileProgressElement.appendChild(progressBar);

        this.fileProgressWrapper.appendChild(this.fileProgressElement);

        document.getElementById(targetID).appendChild(this.fileProgressWrapper);
        fadeIn(this.fileProgressWrapper, 0);

    } else {
        this.fileProgressElement = this.fileProgressWrapper.firstChild;
        this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
    }

    this.height = this.fileProgressWrapper.offsetHeight;

}
FileProgress.prototype.setProgress = function(percentage) {
    this.fileProgressElement.className = "progressContainer green";
    this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
    this.fileProgressElement.childNodes[3].style.width = percentage + "%";
};
FileProgress.prototype.setComplete = function() {
    this.fileProgressElement.className = "progressContainer blue";
    this.fileProgressElement.childNodes[3].className = "progressBarComplete";
    this.fileProgressElement.childNodes[3].style.width = "";

};
FileProgress.prototype.setError = function() {
    this.fileProgressElement.className = "progressContainer red";
    this.fileProgressElement.childNodes[3].className = "progressBarError";
    this.fileProgressElement.childNodes[3].style.width = "";

};
FileProgress.prototype.setCancelled = function() {
    this.fileProgressElement.className = "progressContainer";
    this.fileProgressElement.childNodes[3].className = "progressBarError";
    this.fileProgressElement.childNodes[3].style.width = "";

};
FileProgress.prototype.setStatus = function(status) {
    this.fileProgressElement.childNodes[2].innerHTML = status;
};

FileProgress.prototype.toggleCancel = function(show, swfuploadInstance) {
    this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
    if (swfuploadInstance) {
        var fileID = this.fileProgressID;
        this.fileProgressElement.childNodes[0].onclick = function() {
            swfuploadInstance.cancelUpload(fileID);
            return false;
        };
    }
};

